/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.dataaccess.hibernate;

import cassys.dataaccess.StudentModuleTeamDAO;
import cassys.datatransferobjects.ModuleDTO;
import cassys.datatransferobjects.StudentDTO;
import cassys.datatransferobjects.StudentModuleTeamDTO;
import cassys.datatransferobjects.TeamDTO;
import cassys.exceptions.HibernateAccessLayerException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Lin
 */
public class StudentModuleTeamDAOImpl extends AbstractDao implements StudentModuleTeamDAO  {

    @Override
    public StudentModuleTeamDTO[] findAllStudnetModulTeams() throws HibernateAccessLayerException{
        try {
            List ls = findAll(StudentModuleTeamDTO.class);
            StudentModuleTeamDTO[] list = new StudentModuleTeamDTO[ls.size()];
            ls.toArray(list);
            return list;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public StudentModuleTeamDTO[] findAllStudnetByModule(String moduleCode) throws HibernateAccessLayerException{
         try {
            List ls = super.findAllByParam(StudentModuleTeamDTO.class, "moduleCode", moduleCode);
            StudentModuleTeamDTO[] list = new StudentModuleTeamDTO[ls.size()];
            ls.toArray(list);
            return list;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public StudentModuleTeamDTO[] findAllStudnetByTeam(String teamId) throws HibernateAccessLayerException{
         try {
            List ls = super.findAllByParam(StudentModuleTeamDTO.class, "teamId", teamId);
            StudentModuleTeamDTO[] list = new StudentModuleTeamDTO[ls.size()];
            ls.toArray(list);
            return list;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
    
    @Override
    public StudentModuleTeamDTO findByModule(String moduleCode) throws HibernateAccessLayerException{
        StudentModuleTeamDTO stdModTeam = null;
        try {
            stdModTeam = (StudentModuleTeamDTO) super.findByParam(StudentModuleTeamDTO.class, "moduleCode", moduleCode);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        return stdModTeam;
    }

    @Override
    public StudentModuleTeamDTO findByStudnet(String studentId) throws HibernateAccessLayerException{
        StudentModuleTeamDTO stdModTeam = null;
        try {
            stdModTeam = (StudentModuleTeamDTO) super.findByParam(StudentModuleTeamDTO.class, "studentId", studentId);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        return stdModTeam;
    }

    @Override
    public StudentModuleTeamDTO findByTeam(String teamId) throws HibernateAccessLayerException{
        StudentModuleTeamDTO stdModTeam = null;
        try {
            stdModTeam = (StudentModuleTeamDTO) super.findByParam(StudentModuleTeamDTO.class, "teamId", teamId);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        return stdModTeam;
    }

    @Override
    public void insertStudentModuleTeam(StudentModuleTeamDTO dto) throws HibernateAccessLayerException{
        try {
            //Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting product" + prod.getProductId());
            super.saveOrUpdate(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void updateStudentModuleTeam(StudentModuleTeamDTO dto) throws HibernateAccessLayerException{
        try {
            //Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting product" + prod.getProductId());
            super.saveOrUpdate(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void deleteStudentModuleTeam(StudentModuleTeamDTO dto) throws HibernateAccessLayerException{
        try {
            //Logger.getLogger(getClass().getName()).log(Level.INFO, "Deleting product" + prod.getProductId());
            super.delete(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }   
    
     public StudentModuleTeamDTO[] getAllModulesForStudent(String studentid){
     
           List ls = super.findByCategory(StudentModuleTeamDTO.class,"studentId",studentid);
           StudentModuleTeamDTO[] list = new StudentModuleTeamDTO[ls.size()];
           ls.toArray(list);
           return list;
     }
     
     public StudentModuleTeamDTO[] getAllModulesForTeam(String teamid){
     
           List ls = super.findByCategory(StudentModuleTeamDTO.class,"teamId",teamid);
           StudentModuleTeamDTO[] list = new StudentModuleTeamDTO[ls.size()];
           ls.toArray(list);
           return list;
     }



}
